<?php
error_reporting(E_ALL ^ E_NOTICE);
$board_name = $_REQUEST['board_name'];
$dish_name = $_REQUEST['dish_name'];
$boardId = $_REQUEST['boardId'];
include_once "service.php";
$service = new Dcservice();// 实例化操作
// $service 就是对象了
// $service 是 Dcservice 的对象

?>


<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>点餐系统</title>

    <!-- Bootstrap -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>
<body>


<div class="navbar navbar-default" style="margin-bottom:20px">
    <div class="container-fluid">
        <div class="container">
            <div class="navbar-header">
                <span class="navbar-brand">点餐系统</span>
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            订单管理
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="order2.php">订单列表</a></li>
                            <li><a href="order3.php">订单记录</a></li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            菜品管理 <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="dishadd.php">添加菜品</a></li>
                            <li><a href="dishadd2.php">菜品列表</a></li>
                            <li class="divider"></li>
                            <li><a href="leixingadd.html">添加菜品类型</a></li>
                            <li><a href="leixingadd2.php">菜品类型列表</a></li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            餐桌管理
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="board.html">添加餐桌</a></li>
                            <li><a href="board2.php">餐桌列表</a></li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            登录管理 <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="#" data-toggle="modal" data-target="#aboutModal">关于点餐系统</a></li>
                            <li class="divider"></li>
                            <li><a href="xg.php">修改登录信息</a></li>
                            <li><a href="#exitModal" data-toggle="modal">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
                <div class="modal fade" id="exitModal" tabindex="-1" role="dialog">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title">退出登录</h4>
                            </div>
                            <div class="modal-body">
                                你确定要退出登陆吗？
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default"><a href="logout.php">确定</a></button>
                                <button type="button" class="btn btn-default">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <form action="dc.php">
            <div class="col-xs-2">
                <div class="input-group" style="margin-bottom:20px">
                    <input type="text" name="board_name" class="form-control" placeholder="桌号">
                    <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">
                        <span class="glyphicon glyphicon-search"></span>
                    </button>
                  </span>
                </div>
        </form>
        <ul class="list-group" style="text-align: center">

            <?php
            $conn2= $service->conn2;//调用对象的属性

            $items = $service->getBoards($board_name);//调用对象的方法
            for ($i = 0; $i < count($items); $i++) {
                ?>
                <li class="list-group-item">
                    <a href="./dc.php?boardId=<?php echo $items[$i]['id']; ?>"><?php echo $items[$i]['name'] ?></a>
                </li>
            <?php } ?>


        </ul>
    </div>


    <div class="col-xs-10">
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
            <div class="panel panel-primary" style="margin-bottom:20px">
                <?php
                $data = $service->getorder($boardId);
                $boardNames = $data['boardName'];
                $dishs = $data['dishs'];
                $order_id=$data['orderId'];

                $total = 0.00;
                for ($i = 0; $i < count($dishs); $i++) {
                    $total += $dishs[$i]['price'];
                }
                ?>

                <div class="panel-heading" role="tab" id="headingOne">
                    <h4 class="panel-title glyphicon glyphicon-<?php echo !isset($boardNames) ? 'remove' : 'ok' ?>">
                        <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"
                           aria-expanded="true" aria-controls="collapseOne">
                            <?php echo isset($boardNames) ? $boardNames : '没有选餐桌' ?>
                        </a>
                    </h4>
                    <span style="text-align: right">
                            <a href="./jz.php?orderId=<?php echo $order_id; ?>"
                               class="btn btn-success btn-sm pull-right">
                                结账
                                <span class="badge"><?php echo isset($total) ? $total : 0; ?>元</span>
                            </a></span>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
                     aria-labelledby="headingOne">
                    <div class="panel-body" style="text-align: center">
                        <?php
                        for ($i = 0; $i < count($dishs); $i++) {
                            $dish = $dishs[$i];
                            ?>
                            <div class="col-xs-4 col-md-3 col-lg-3" style="margin-bottom: 10px">
                                <div class="thumbnail">
                                    <img src="<?php echo $dish['icon']; ?>">
                                    <div class="caption">
                                        <?php echo $dish['dish_name'] . ' ' . $dish['price'] . '元'; ?>
                                        <a href="./del.php?id=<?php echo $dish['oid']; ?>&boardId=<?php echo $boardId ?>">取消</a>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>


                    </div>
                </div>
            </div>
        </div>
        <form action="dc.php">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="row">
                        <div class="col-lg-6">
                        <span class="glyphicon glyphicon-th-list"
                              style="margin-right:5px;"></span>
                            可选菜品
                        </div>
                        <div class="col-lg-6">
                            <div class="input-group">
                                <input type="text" name="dish_name" class="form-control" placeholder="菜名">
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle"
                                            data-toggle="dropdown" style="border-radius: 0;">全部<span
                                                class="caret"></span>
                                    </button>
                                    <select class="dropdown-menu dropdown-menu-right">
                                        <option>hh</option>
                                        <?php
                                        $pp = $service->getleixing($p);
                                        var_dump($pp);
                                        for ($i = 0; $i < count($pp); $i++) {
                                        } ?>
                                        <option value="<?php echo $pp[$i]['id']; ?>"><?php echo $pp[$i]['type_name']; ?></option>
                                    </select>
                                </div>
                                <div class="input-group-btn">
                                    <button type="submit" class="btn btn-default" style="width: 50px">
                                        <span class="glyphicon glyphicon-search"></span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="panel-body">
                    <div class="row" style="text-align: center">
                        <?php
                        $itemos = $service->getdish($dish_name);

                        for ($i = 0; $i < count($itemos); $i++) {
                            $list = $itemos[$i];
                            ?>
                            <div class="col-xs-4 col-md-3 col-lg-3" style="margin-bottom: 10px">
                                <div class="thumbnail">
                                    <img src="<?php echo $list['icon']; ?>">
                                    <div class="caption">
                                        <a href="./order.php?boardId=<?php echo $boardId; ?>&dishId=<?php echo $list['id']; ?>"><?php echo $list['dish_name'] . ' ' . $list['price'] . '元'; ?></a>
                                    </div>
                                </div>
                            </div>
                        <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="./js/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="./js/bootstrap.min.js"></script>
<script type="text/javascript">
    $.fn.serializeObject = function () {
        // 声明一个空Json对象
        var o = {};
        // 将被选中的form转换为数组
        var a = this.serializeArray();
        // 循环数组
        $.each(a, function () {
            // 判断 Json 对象中有没有 指定的属性
            if (o[this.name]) {
                // 判断这个属性是否支持数组和方法
                if (!o[this.name].push) {
                    // 不支持 就在Json对象中新增加一个数组属性
                    o[this.name] = [o[this.name]];
                }
                // 支持 就将循环的值加入到数组
                o[this.name].push(this.value || '');
            } else {
                // 在Json对象中新增加一个属性
                o[this.name] = this.value || '';
            }
        });
        return o;
    };



</script>
</body>
</html>